﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace MadPropsDemo
{
    public class CommandsBase
    {
        public static Func<Exception, bool> RescueAction = null;

        protected ICommand ForDelegate(Action action)
        {
            return new DelegateCommand(() =>
            {
                try
                {
                    action();
                }
                catch (Exception ex)
                {
                    bool shouldThrow = true;

                    if (RescueAction != null)
                    {
                        shouldThrow = !RescueAction(ex);
                    }

                    if (shouldThrow)
                    {
                        throw;
                    }
                }
            });
        }
    }
}
